package com.hmall.order.web;


import com.hmall.common.pojo.Order;
import com.hmall.order.service.IOrderService;
import com.hmall.order.web.request.OrderRequest;
import com.hmall.order.web.response.OrderVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @GetMapping("{id}")
    public OrderVO queryOrderById(@PathVariable("id") Long orderId) {
        Order order = orderService.getById(orderId);
        OrderVO orderVO = new OrderVO();
        BeanUtils.copyProperties(order, orderVO);
        orderVO.setTotalFee(order.getTotalFee() * 1.00);
        return orderVO;
    }

    @PostMapping
    public Long createOrder(@RequestBody OrderRequest orderRequest) {
        return orderService.createOrder(orderRequest);
    }
}
